package com.itheima.service.cargo.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.dao.cargo.InvoiceDao;
import com.itheima.domain.cargo.Invoice;
import com.itheima.domain.cargo.InvoiceExample;
import com.itheima.service.cargo.InvoiceService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
@Service
public class InvoiceServiceImpl implements InvoiceService {
    @Autowired
    private InvoiceDao invoiceDao;
    @Override
    public Invoice findById(String id) {
        return invoiceDao.selectByPrimaryKey(id);
    }

    @Override
    public void save(Invoice invoice) {
        invoiceDao.insert(invoice);
    }

    @Override
    public void update(Invoice invoice) {
        invoiceDao.updateByPrimaryKey(invoice);
    }

    @Override
    public void delete(String id) {
        invoiceDao.deleteByPrimaryKey(id);
    }

    @Override
    public PageInfo findByPage(int pageNum, int pageSize, InvoiceExample example) {
        //设置分页参数
        PageHelper.startPage(pageNum,pageSize);
        //查询全部
        List<Invoice> list = invoiceDao.selectByExample(example);
        //构造返回值
        return new PageInfo(list);
    }
}
